package session;
import java.rmi.RemoteException;
import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
import javax.ejb.Handle;
import javax.ejb.Remove;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;
import javax.ejb.Stateful;

import entity.Item;
import entity.User;

@Stateful(name="YourCart", mappedName="ejb/YourCart")
public class CartBean implements Cart {
	private ArrayList<Item> items;
	private User owner;
    //protected SessionContext ctx;

    //@PostConstruct
    public void initialize(User user) {
        items = new ArrayList<Item>();
        owner=user;        
    }
    public void addItem(Item item) {
        items.add(item);
    }
    public void removeItem(Item item) {
        items.remove(item);
    }
    public ArrayList<Item> getItems() {
        return items;
    }
    public void setOwner(User user){
    	this.owner=user;
    }
	public User getOwner() {
		return null;
	}
//	public void setSessionContext(javax.ejb.SessionContext ctx) throws RemoteException {
//	    this.ctx = ctx;
//	}
	@Remove
	public void remove(){
		items = new ArrayList<Item>();
		owner = new User();
	}
}